<template>
  <div>
    <div class="form">
      <div class="search">
        <el-input placeholder="客户名称" v-model="customerName" class="search_info">
          <i slot="prefix" class="el-input__icon el-icon-search"></i>
        </el-input>
        <el-select v-model="branchNo" placeholder="区域" class="search_info">
          <el-option
            v-for="item in branchNoList"
            :key="item.key"
            :label="item.value"
            :value="item.key"
          ></el-option>
        </el-select>
        <el-select v-model="ruleLevel" placeholder="预警信号" class="search_info">
          <el-option
            v-for="item in ruleLevelList"
            :key="item.key"
            :label="item.value"
            :value="item.key"
          ></el-option>
        </el-select>
        <el-select v-model="bizSource" placeholder="业务类型" class="search_info">
          <el-option
            v-for="item in bizSourceList"
            :key="item.key"
            :label="item.value"
            :value="item.key"
          ></el-option>
        </el-select>
        <div class="pos_right_btn">
          <el-button @click="reset()">重置</el-button>
          <el-button type="primary" @click="getList(1)" class="searchBtn">搜索</el-button>
        </div>
      </div>
      <el-table
        class="listTable"
        ref="multipleTable"
        v-loading="listLoading"
        :data="list"
        border
        fit
        highlight-current-row
        style="width: 100%;"
        @selection-change="handleSelectionChange"
      >
        <!-- <el-table-column type="selection" >
          
        </el-table-column>-->
        <el-table-column label="授信编号" sortable prop="id" width="100" align="center">
          <template slot-scope="{row}">
            <span>{{ row.approveId }}</span>
          </template>
        </el-table-column>
        <el-table-column label="客户名称" align="center">
          <template slot-scope="{row}">
            <span>{{ row.customerName }}</span>
          </template>
        </el-table-column>
        <el-table-column label="区域" align="center">
          <template slot-scope="{row}">
            <span>{{ row.branchName }}</span>
          </template>
        </el-table-column>
        <el-table-column label="产品名称" width="160" align="center">
          <template slot-scope="{row}">
            <span>{{ row.productName }}</span>
            <span v-if="!row.productName">定制需求</span>
          </template>
        </el-table-column>
        <el-table-column label="授信开始时间" align="center">
          <template slot-scope="{row}">
            <span>{{ row.approveStart }}</span>
          </template>
        </el-table-column>
        <el-table-column label="授信结束时间" align="center">
          <template slot-scope="{row}">
            <span>{{ row.approveEnd }}</span>
          </template>
        </el-table-column>
        <el-table-column label="担保方式" align="center">
          <template slot-scope="{row}">
            <span v-if="row.guaranteeType == '' || row.guaranteeType == 9">不限</span>
            <span v-if="row.guaranteeType === '0'">抵押</span>
            <span v-if="row.guaranteeType == 1">质押</span>
            <span v-if="row.guaranteeType == 2">信用</span>
            <span v-if="row.guaranteeType == 3">一般保证</span>
          </template>
        </el-table-column>
        <el-table-column label="授信额度(万元)" align="center">
          <template slot-scope="{row}">
            <span>{{ row.approveAmount }}</span>
          </template>
        </el-table-column>
        <el-table-column label="贷款余额(万元)" align="center">
          <template slot-scope="{row}">
            <span>{{ row.balance }}</span>
          </template>
        </el-table-column>
        <el-table-column label="预警信号" align="center">
          <template slot-scope="{row}">
            <span>{{ row.ruleLevelName }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="160" align="center">
          <template slot-scope="{row}">
            <div class="opt_table">
              <div class="opt_font" @click="lauch()">发起催收</div>
              <div class="opt_font" @click="preview(row.customerId)">查看详情</div>
              <!-- <div class="opt_font opt_disable" v-if="row.mortgageStatus == '1'">已抵押</div> -->
              <!-- <div class="opt_font">更多</div> -->
            </div>
          </template>
        </el-table-column>
      </el-table>
      <div class="footer">
        <div class="footer_btn">
          <!-- <el-button type="primary">批量抢单</el-button> -->
        </div>
        <el-pagination
          :total="total"
          layout="total, sizes, prev, pager, next"
          :page-size="limit"
          :page-sizes="[10, 20, 50, 100]"
          @size-change="handleSizeChange"
          :current-page.sync="curPage"
          @current-change="getList($event)"
          class="sortStyle"
        />
      </div>
      <div class="pre">
        <el-dialog :visible.sync="detailShow" :title="infoTitle" width="1096px">
          <div>
            <div class="detail_title pos_top">
              <span></span>
              预警信息
            </div>
            <el-table
              class="detailTable"
              v-loading="listLoading"
              :data="detailData"
              border
              fit
              highlight-current-row
              style="width: 100%;"
            >
              <el-table-column label="序号" prop="id" align="center">
                <template slot-scope="{row}">
                  <span>{{ row.index }}</span>
                </template>
              </el-table-column>
              <el-table-column label="预警时间" align="center">
                <template slot-scope="{row}">
                  <span>{{ row.warnDate }}</span>
                </template>
              </el-table-column>
              <el-table-column label="预警等级" align="center">
                <template slot-scope="{row}">
                  <span>{{ row.warnLevelName }}</span>
                </template>
              </el-table-column>
              <el-table-column label="触发信号" align="center">
                <template slot-scope="{row}">
                  <span>{{ row.warnSignal }}</span>
                </template>
              </el-table-column>
            </el-table>
            <div class="detail_title pos_top">
              <span></span>
              需求信息
            </div>
            <el-table
              class="detailTable"
              v-loading="listLoading"
              :data="needData.bizApplyInfoList"
              border
              fit
              highlight-current-row
              style="width: 100%;"
            >
              <el-table-column label="需求编号" prop="id" align="center">
                <template slot-scope="{row}">
                  <span>{{ row.id }}</span>
                </template>
              </el-table-column>
              <el-table-column label="企业名称" align="center">
                <template slot-scope="{row}">
                  <span>{{ row.customerName }}</span>
                </template>
              </el-table-column>
              <el-table-column label="申请产品" align="center">
                <template slot-scope="{row}">
                  <span>{{ row.productName }}</span>
                  <span v-if="!row.productName">定制需求</span>
                </template>
              </el-table-column>
              <el-table-column label="担保方式" align="center">
                <template slot-scope="{row}">
                  <span v-if="row.guaranteeType == '' || row.guaranteeType == 9">不限</span>
                  <span v-if="row.guaranteeType === '0'">抵押</span>
                  <span v-if="row.guaranteeType == 1">质押</span>
                  <span v-if="row.guaranteeType == 2">信用</span>
                  <span v-if="row.guaranteeType == 3">一般保证</span>
                </template>
              </el-table-column>
              <el-table-column label="融资金额(万元)" align="center">
                <template slot-scope="{row}">
                  <span>{{ row.financeAmount }}</span>
                </template>
              </el-table-column>
              <el-table-column label="融资期限(月)" align="center">
                <template slot-scope="{row}">
                  <span>{{ row.financeTime }}</span>
                </template>
              </el-table-column>
            </el-table>
            <div class="detail_title pos_top">
              <span></span>
              授信信息
            </div>
            <el-table
              class="detailTable"
              v-loading="listLoading"
              :data="needData.bizApproveInfoList"
              border
              fit
              highlight-current-row
              style="width: 100%;"
            >
              <el-table-column label="授信合同号" prop="id" align="center">
                <template slot-scope="{row}">
                  <span>{{ row.id }}</span>
                </template>
              </el-table-column>
              <el-table-column label="是否首贷" align="center">
                <template slot-scope="{row}">
                  <span v-if="row.ifFirstApprove == 0">是</span>
                  <span v-if="row.ifFirstApprove == 1">否</span>
                </template>
              </el-table-column>
              <el-table-column label="授信开始日" align="center">
                <template slot-scope="{row}">
                  <span>{{ row.approveStart }}</span>
                </template>
              </el-table-column>
              <el-table-column label="授信到期日" align="center">
                <template slot-scope="{row}">
                  <span>{{ row.approveEnd }}</span>
                </template>
              </el-table-column>
            </el-table>
            <div class="detail_title pos_top">
              <span></span>
              综合授信
            </div>
            <el-table
              class="detailTable"
              v-loading="listLoading"
              :data="needData.approveDetailList"
              border
              fit
              highlight-current-row
              style="width: 100%;"
            >
              <el-table-column label="序号" type="index" align="center"></el-table-column>
              <el-table-column label="担保类型" align="center">
                <template slot-scope="{row}">
                  <span v-if="row.guaranteeType == '' || row.guaranteeType == 9">不限</span>
                  <span v-if="row.guaranteeType === '0'">抵押</span>
                  <span v-if="row.guaranteeType == 1">质押</span>
                  <span v-if="row.guaranteeType == 2">信用</span>
                  <span v-if="row.guaranteeType == 3">一般保证</span>
                </template>
              </el-table-column>
              <el-table-column label="授信金额(万元) " align="center">
                <template slot-scope="{row}">
                  <span>{{ row.approveAmount }}</span>
                </template>
              </el-table-column>
            </el-table>
            <div class="detail_title pos_top">
              <span></span>
              放款信息
            </div>
            <el-table
              class="detailTable"
              v-loading="listLoading"
              :data="needData.bizLoanInfoList"
              border
              fit
              highlight-current-row
              style="width: 100%;"
            >
              <el-table-column label="序号" type="index" align="center"></el-table-column>
              <el-table-column label="放款合同号" align="center">
                <template slot-scope="{row}">
                  <span>{{ row.approveContractNo }}</span>
                </template>
              </el-table-column>
              <el-table-column label="放款金额(万元)" align="center">
                <template slot-scope="{row}">
                  <span>{{ row.approveAmount }}</span>
                </template>
              </el-table-column>
              <el-table-column label="放款利率（%）" align="center">
                <template slot-scope="{row}">
                  <span>{{ row.loanRatio }}</span>
                </template>
              </el-table-column>
              <el-table-column label="贷款起始日" align="center">
                <template slot-scope="{row}">
                  <span>{{ row.approveStart }}</span>
                </template>
              </el-table-column>
              <el-table-column label="贷款到期日" align="center">
                <template slot-scope="{row}">
                  <span>{{ row.approveEnd }}</span>
                </template>
              </el-table-column>
              <el-table-column label="未归还金额(万元)" align="center">
                <template slot-scope="{row}">
                  <span>{{ row.balance }}</span>
                </template>
              </el-table-column>
            </el-table>
          </div>
        </el-dialog>
      </div>
    </div>
  </div>
</template>

<script>
import {
  detailList,
  warnSignalDetail,
  warnSignalList,
  createPledge,
  uploadFile,
  getBizApproveInfo,
  insertLoanInfo,
  allapproveList,
  dictType
} from "@/api/system/user";
import { MessageBox } from "element-ui";
export default {
  components: {},
  data() {
    return {
      userName: "",
      areaCode: "",
      work: "",
      load: "",
      date: "",
      value: "",
      status: [],
      list: [],
      listLoading: false,
      total: 0,
      limit: 10,
      curPage: 1,
      listData: [],
      detailShow: false,
      needData: [],
      customerName: "",
      productName: "",
      mortgageStatus: "",
      mortgageList: [],
      addLoanShow: false,
      reqId: "",
      customerId: "",
      flowUid: "",
      approveId: "",
      loanContractNo: "",
      loanAmount: "",
      guaranteeType: "",
      loanRatio: "",
      loanStart: "",
      loanEnd: "",
      dealShow: false,
      rowData: [],
      propertyCard: "",
      propertyPerson: "",
      loanFile: "",
      pledgeFile: "",
      branchNo: "",
      bizSource: "",
      bizSourceList: [
        {
          key: "-1",
          value: "全部业务"
        },
        {
          key: "0",
          value: "线上业务"
        },
        {
          key: "1",
          value: "存量业务"
        }
      ],
      ruleLevel: "",
      branchNoList: [],
      ruleLevelList: [],
      detailData: [],
      infoTitle: ""
    };
  },
  created() {},
  mounted() {
    this.leave();
    this.getArea();
    this.getList(1);
  },
  methods: {
    lauch() {
      this.$message("即将发布，敬请期待。");
    },
    //leave
    leave() {
      dictType("warn_level").then(res => {
        res.data.forEach(element => {
          this.ruleLevelList.push({
            key: element.dictValue,
            value: element.dictLabel
          });
        });
      });
    },
    //area
    getArea() {
      dictType("area_codes").then(res => {
        res.data.forEach(element => {
          this.branchNoList.push({
            key: element.dictValue,
            value: element.dictLabel
          });
        });
      });
    },
    reset() {
      this.customerName = "";
      this.branchNo = "";
      this.ruleLevel = "";
      this.bizSource = "";
    },
    order(id) {
      var params = {
        reqId: id
      };
      this.listLoading = true;
      checkIn(id).then(response => {
        this.listLoading = false;
      });
    },
    /** 查询用户列表 */
    getList(page) {
      var params = {
        pageNum: page,
        pageSize: this.limit,
        customerName: this.customerName,
        branchNo: this.branchNo,
        ruleLevel: this.ruleLevel,
        bizSource: this.bizSource
      };
      this.listLoading = true;
      warnSignalList(params).then(response => {
        this.list = response.rows;
        this.list.forEach(element1 => {
          this.branchNoList.forEach(element2 => {
            if (element1.branchNo == element2.key) {
              element1.branchName = element2.value;
            }
          });
          this.ruleLevelList.forEach(element2 => {
            if (element1.ruleLevel == element2.key) {
              element1.ruleLevelName = element2.value;
            }
          });
        });
        this.total = response.total;
        this.listLoading = false;
      });
    },
    //多选
    handleSelectionChange(rows) {
      console.log(rows);
    },
    goback() {
      this.detailShow = false;
    },
    handleSizeChange(val) {
      this.limit = val;
      this.getList(1);
    },
    //任务详情
    preview(id) {
      this.detailShow = true;
      warnSignalDetail(id).then(response => {
        this.needData = response.data;
        this.infoTitle = response.data.name;
      });
      detailList(id).then(response => {
        this.detailData = response.rows;
        this.detailData.forEach(element1 => {
          this.ruleLevelList.forEach(element2 => {
            if (element1.warnLevel == element2.key) {
              element1.warnLevelName = element2.value;
            }
          });
        });
      });
    }
  }
};
</script>
<style scoped>
.form {
  padding-left: 26px;
  padding-right: 24px;
  padding-top: 24px;
  background: #fff;
}
.search {
  display: flex;
  position: relative;
}
.search_info {
  width: 120px;
  height: 40px;
  margin-right: 16px;
}
.searchBtn {
  margin-left: 16px;
  height: 36px;
}
.sortStyle {
  height: 19px;
  float: right;
  /* right: 24px; */
  margin-top: 20px;
  margin-bottom: 30px;
}
.pos_right_btn {
  position: absolute;
  right: 0;
}
.opt_font {
  cursor: pointer;
  color: #2e82ff;
}
.detail_title {
  font-size: 16px;
  font-weight: 400;
  color: #212121;
  line-height: 22px;
}
.detail_title span {
  padding-left: 4px;
  background: #1e88e5;
  margin-right: 12px;
}
.row {
  display: flex;
  /* padding-bottom: 12px; */
}
.detail_info {
  padding-top: 16px;
}
.info_left {
  display: flex;
}
.info_right {
  display: flex;
  /* padding-left: 202px; */
}
.info_left_title {
  font-size: 14px;
  font-weight: 400;
  color: #616161;
  line-height: 20px;
  width: 256px;
  /* margin-right: 16px; */
  text-align: center;
  min-height: 47px;
  background: #f5f7fa;
  box-shadow: inset 0 -1px 0 0 #dcdfe6;
}
.info_left_title .font {
  position: relative;
  top: 14px;
}
.info_left_content {
  font-size: 14px;
  font-weight: 400;
  color: #212121;
  line-height: 20px;
  width: 256px;
  /* border: 1px solid #DCDFE6; */
  box-shadow: inset -1px -1px 0 0 #dcdfe6;
  text-align: center;
}
.info_left_contents {
  font-size: 14px;
  font-weight: 400;
  color: #212121;
  line-height: 20px;
  width: 769px;
  /* border: 1px solid #DCDFE6; */
  box-shadow: inset -1px -1px 0 0 #dcdfe6;
  text-align: center;
}
.pos_top {
  padding-top: 12px;
}
.top_more {
  margin-top: 8px;
}
.detailTable {
  margin-top: 16px;
}
.opt_font {
  color: #1e88e5;
  cursor: pointer;
}
.page_pos {
  text-align: right;
  padding-top: 10px;
}
.backBtn {
  text-align: center;
  margin-top: 10px;
}
/deep/ .el-dialog {
  display: flex;
  flex-direction: column;
  margin: 0 !important;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  max-height: calc(100% -30px);
  /* max-width: ; */
}
/deep/ .el-dialog .el-dialog__body {
  /* flex: 1; */
  height: 600px;
  overflow-y: auto;
  padding-top: 0;
}
.pre /deep/ .el-dialog__body {
  height: 700px;
}
.tab {
  display: flex;
  position: absolute;
  right: 32px;
  top: 14px;
}
.tab_border {
  border: 1px solid #409eff;
  color: #409eff;
  padding: 10px 12px;
  font-size: 14px;
  margin-right: 16px;
}
.change {
  border: 1px solid #f56c6c;
  color: #f56c6c;
}
.listTable {
  margin-top: 17px;
}
/deep/ .search_info .el-input__inner {
  width: 120px;
}
.date_picker /deep/ .el-input__inner {
  width: 240px;
}
.opt_table {
  display: flex;
  justify-content: space-around;
}
.footer {
  display: flex;
  justify-content: space-between;
}
.footer_btn {
  position: relative;
  top: 20px;
}
.opt_disable {
  color: #909399;
}
.centers {
  /* display: flex; */
  text-align: center;
}
.pad_top {
  padding-bottom: 16px;
}
.flex_row {
  display: flex;
  justify-content: center;
}
.font_info {
  width: 80px;
  position: relative;
  top: 8px;
}
.input_info {
  width: 200px;
}
.left_style {
  display: flex;
  padding-bottom: 16px;
}
.left_style .font {
  width: 130px;
  text-align: right;
  margin-right: 20px;
  position: relative;
  top: 8px;
}
.deal_style {
  display: flex;
  justify-content: center;
}
.backBtns {
  text-align: center;
  /* margin-top:10px; */
}
</style>
